<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>附件管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <#include "../../include/layui.ftl" />
    <#include "../../include/pTable.ftl" />
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <form  id="queryForm">
                <input type="hidden" id="className" name="className" value="${className!}" />
                <input type="hidden" id="modleName" name="modleName" value="${modleName!}" />
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">附件名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="original" placeholder="请输入" autocomplete="off" class="layui-input">
                            <input type="hidden" name="original_searchType" value="like">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">附件路径</label>
                        <div class="layui-input-block">
                            <input type="text" name="url" placeholder="请输入" autocomplete="off" class="layui-input">
                            <input type="hidden" name="url_searchType" value="like">
                        </div>
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card-body">
            <table id="lay-table" lay-filter="lay-table"></table>
            <script type="text/html" id="toolbar"></script>
        </div>
    </div>
</div>
<script>
    function conver(limit){
        var size = "";
        if( limit < 0.1 * 1024 ){ //如果小于0.1KB转化成B
            size = limit.toFixed(1) + "B";
        }else if(limit < 0.1 * 1024 * 1024 ){//如果小于0.1MB转化成KB
            size = (limit / 1024).toFixed(1) + "KB";
        }else if(limit < 0.1 * 1024 * 1024 * 1024){ //如果小于0.1GB转化成MB
            size = (limit / (1024 * 1024)).toFixed(1) + "MB";
        }else{ //其他转化成GB
            size = (limit / (1024 * 1024 * 1024)).toFixed(1) + "GB";
        }

        var sizestr = size + "";
        var len = sizestr.indexOf("\.");
        var dec = sizestr.substr(len + 1, 1);
        if(dec == "0"){//当小数点后为00时 去掉小数部分
            return sizestr.substring(0,len) + sizestr.substr(len + 3,1);
        }
        return sizestr;
    }

    layui.config({
        base: '${path}/plug-in/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','tables','upload','layer','layers'],function () {
        var tables = layui.tables,
            $ = layui.$,
            upload = layui.upload,
            layer = layui.layer,
            layers = layui.layers,
            table = layui.table;
        var parmer = {
            cols:[[
                    {type:'numbers'}
                    ,{field:"type",width:200,title:"文件类型"}
                    ,{field:"original",width:200,title:"附件名称"}
                    ,{field:"size",width:200,title:"附件大小",templet:function (row) {
                        return conver(row.size);
                    }}
                    ,{field:"title",width:200,title:"新名称"}
                    ,{field:"url",width:200,title:"完整路径"}
                    ,{field:"state",width:200,title:"上传状态"}
                ]]
        };
        var $tables = tables.renderTable(parmer);

        //头工具栏事件
        table.on('toolbar(lay-table)', function(obj){
            switch(obj.event){
                case '05':
                    var where = $("#queryForm").serializeObject();
                    $tables.reload({
                        where: where,
                        text: {none: '暂无数据！'}
                    });
                    break;
                case "06":
                    layer.open({
                        type: 2,
                        title: '文件上传测试',
                        content: '/console/attachment/rewrite/upload',
                        area:['600px', '400px'],
                        btn:['关闭'],
                        yes: function(index){
                            layer.close(index);
                            var where = $("#queryForm").serializeObject();
                            $tables.reload({
                                where: where,
                                text: {none: '暂无数据！'}
                            });
                        }
                    });
                    break;
                case "28":
                    if($.isEmptyObject(p.data)){
                        layer.msg("请先选择一条数据");
                        return;
                    }
                    layers.openWindowInHidden({url:"/console/download?id="+p.data.id});
                    break;
            };
        });
    });
</script>
</body>
</html>